<template>
	<view>
		<fa-navbar :title="$t('step.pastweeks')" :border-bottom="false"></fa-navbar>

		<view class="split"></view>
		<view class="weekTime" v-for="(item, index) in past_weeks" :key="index">
			<view class="weekTitle">
				<view>{{$t('step.week')}} {{index}} {{$t('common.of')}} {{weeks}} </view>
			</view>
			<view class="weekFlex">
				<view class="week">
					<view class="top">
						{{$t('common.week.sunday')}}
					</view>
					<view :class="getClass(item['0'],0,index)">
					</view>
					<view class="bottom">
						{{item['0']}}
					</view>
				</view>
				<view class="week">
					<view class="top">
						{{$t('common.week.monday')}}
					</view>
					<view :class="getClass(item['1'],1,index)">
					</view>
					<view class="bottom">
						{{item['1']}}
					</view>

				</view>
				<view class="week">
					<view class="top">
						{{$t('common.week.tuesday')}}
					</view>
					<view :class="getClass(item['2'],2,index)">

					</view>
					<view class="bottom">
						{{item['2']}}
					</view>
				</view>
				<view class="week">
					<view class="top">
						{{$t('common.week.wednesday')}}
					</view>
					<view :class="getClass(item['3'],3,index)">

					</view>
					<view class="bottom">
						{{item['3']}}
					</view>
				</view>
				<view class="week">
					<view class="top">
						{{$t('common.week.thursday')}}
					</view>
					<view :class="getClass(item['4'],4,index)">

					</view>
					<view class="bottom">
						{{item['4']}}
					</view>
				</view>
				<view class="week">
					<view class="top">
						{{$t('common.week.friday')}}
					</view>
					<view :class="getClass(item['5'],5,index)">

					</view>
					<view class="bottom">
						{{item['5']}}
					</view>
				</view>
				<view class="week">
					<view class="top">
						{{$t('common.week.saturday')}}
					</view>
					<view :class="getClass(item['6'],6,index)">

					</view>
					<view class="bottom">
						{{item['6']}}
					</view>
				</view>
			</view>
		</view>

	</view>
</template>

<script>
	export default {
		data() {
			return {
				order_id: 0,
				past_weeks: [],
				past_weeks_length: 0,
				weeks_num: 0,
				weeks_span: 0,
				weeks: 0,
				today_week: 0
			}
		},
		onLoad(option) {
			this.order_id = option.id
			this.getPastWeeks(this.order_id)
		},
		methods: {
			getClass(steps, week, weeks_num) {
				let step_class = 'unknow'
				if (steps >= 9000) {
					step_class = "power"
				} else if (steps >= 7400 && steps < 9000) {
					step_class = "active"
				} else if (steps > 0 && steps < 7400) {
					step_class = "lost"
				} else {
					step_class = 'unknow'
				}
				if (week == this.today_week && weeks_num == this.weeks_span) {
					step_class += ' stepping';
				}
				return step_class;
			},
			getPastWeeks(id) {
				this.$api.activityOrderPastWeeks({
					id: id
				}).then(res => {
					if (res.code == 1) {
						this.past_weeks = res.data.list
						//console.log(this.past_weeks)
						this.past_weeks_length = res.data.length
						this.today_week = res.data.today_week
						this.weeks_span = res.data.weeks_span
						this.weeks_num = res.data.weeks_num
						this.weeks = res.data.weeks
					}
				})
			}

		}
	}
</script>

<style lang="scss" scoped>
	.weekTime {
		height: 180px;
		background-color: #fff;

		.weekTitle {
			font-weight: bold;
			font-size: 13px;
			padding: 10px 10px 10px 10px;
			color: #6c7379;
			display: flex;
			justify-content: space-between;
		}

		.weekFlex {
			height: 120px;
			display: flex;
			color: #ebfbee;
			border-bottom: #e5e5e5 solid 1px;
			// background-color: #ebfbee;

			.week {
				text-align: center;
				width: 60px;

				// background-color: #888;
				.top {
					text-align: center;
					padding-top: 10px;
					font-size: 14px;
					color: #868e96;
				}

				.unknow {
					margin: 10px auto;
					height: 35px;
					width: 35px;
					font-size: 22px;
					line-height: 35px;

					border-radius: 35px;
					border: 1px dashed #B7BAC3;
				}

				.stepping {
					border: 1px dashed #fff !important;
				}

				.lost {
					margin: 10px auto;
					height: 35px;
					width: 35px;
					font-size: 22px;
					line-height: 35px;
					background-color: #ccc;
					border-radius: 35px;
					border: 1px solid #B7BAC3;
				}

				.power {
					margin: 10px auto;
					height: 35px;
					width: 35px;
					font-size: 22px;
					line-height: 35px;
					background-color: #29BC64;
					background-image: url("../../static/image/power.png");
					background-size: 80% 80%;
					background-position: 50% 50%;
					background-repeat: no-repeat;
					border-radius: 35px;
					border: 1px solid #29BC64;
				}

				.active {
					margin: 10px auto;
					height: 35px;
					width: 35px;
					font-size: 22px;
					line-height: 35px;
					background-color: #C1E804;
					background-image: url("../../static/image/right.png");
					background-size: 65% 65%;
					background-position: 50% 50%;
					background-repeat: no-repeat;
					border-radius: 35px;
					border: 1px solid #C1E804;
				}

				.bottom {
					text-align: center;

					font-size: 14px;
					color: #868e96;
				}
			}



		}
	}

	.split {
		border-top: #eeeeee solid 1px;
		border-bottom: #eeeeee solid 1px;
		height: 10px;
		background-color: #ebfbee;
	}

	.wrap {
		display: flex;
		flex-direction: column;
		height: calc(100vh - var(--window-top));
		width: 100%;
	}
</style>